\section{Introduction}

The \commonlisp{} standard \cite{ansi:common:lisp} contains many
references to environments.  Most of these references concern
\emph{lexical} environments at \emph{compile time}, because they are
needed in order to process forms in non-null lexical environments.
The standard does not specify the nature of these objects, though in
the book ``Common Lisp, the Language, second edition''
\cite{Steele:1990:CLL:95411} (henceforth referred to as ``CLtL2'')
there is a suggested protocol that is supplied by some existing
\commonlisp{} implementations.

The protocol documented in CLtL2 has several problems.  Functions in
the protocol return multiple values, a fact that makes the protocol
hard to extend.  Furthermore, the protocol is incomplete.  A typical
compiler needs more information than the protocol provides, making
implementation-specific extensions obligatory for the protocol to be
useful.  For that reason, although existing \commonlisp{}
implementations often provide such extensions, the CLtL2 protocol is
not what the native compiler of the implementation actually uses.

In this paper, we propose a modern alternative protocol based on
\clos{}.  Rather than returning multiple values, our protocol
functions return instances of standard classes.  Accessors for those
instances can be used by compilers and other \emph{code walker}
applications in order to obtain the information needed for the task to
be accomplished.  This protocol is defined and implemented in the
\trucler{} library.%
\footnote{https://github.com/s-expressionists/Trucler}

Two of the functions in the section about environments in CLtL2 are
not discussed in this paper, namely \texttt{parse-macro} and
\texttt{enclose}.  These functions do not contribute any functionality
to the protocol being described, and the interface provided by these
functions does not require any modifications, which is why they are
not discussed here.  The function \texttt{enclose} requires an
evaluator such as a compiler or an interpreter, and the evaluator will
certainly \emph{use} the functionality in the protocol, but not add to
it.  The function \texttt{parse-macro} does not seem to even use this
functionality, and indeed the optional \textit{env} parameter of this
function is declared \texttt{ignore} both in \sbcl{} and \ccl{}.

Although \texttt{parse-macro} and \texttt{enclose} are essential for
any code-walking application, the purpose of the current work is not
to provide a complete implementation-independent library for code
walking, but just to propose an alternative protocol for accessing
lexical environments.

%%  LocalWords:  startup runtime
